package weixin.processer.event;

import models.User;
import models.UserProp;
import play.Logger;
import weixin.WXMessage;

/**
 * 取消关注事件处理器
 * 
 * @author ultrafrog
 * @version 1.0, 2014-11-10
 * @since 1.0
 */
public class UnsubscribeEventProcesser extends WXEventProcesser {

	/* (non-Javadoc)
	 * @see weixin.processer.event.WXEventProcesser#process(weixin.WXMessage, weixin.WXMessage)
	 */
	@Override
	public Boolean process(WXMessage wxmsg, WXMessage bkmsg) {
		Logger.info("it's unsubscribe event.");
		User user = User.find("byOpenId", wxmsg.fromUserName).first();
		if (user != null) {
			UserProp userProp = UserProp.find("byUser", user.id).first();
			userProp.subscribe = UserProp.Subscribe.UNSUBSCRIBE;
			userProp.save();
		}
		return Boolean.TRUE;
	}
}
